package com.cloud.dynamic.gateway.controller;

import com.cloud.dynamic.gateway.service.NacosGatewayRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * @author amber
 */
@RequestMapping("/nacos")
@RestController
public class NacosController {
    @Autowired
    private NacosGatewayRulesService gatewayRuleService;

    @PostMapping("/add")
    public String create(@RequestBody RouteDefinition entity) {
        String result = "OK";
        gatewayRuleService.add(entity);
        return result;
    }

    @RequestMapping("/list")
    public Flux<RouteDefinition> list() {
        return gatewayRuleService.list();
    }

    @RequestMapping("/remove")
    public void remove(@RequestParam String dataId) {
        gatewayRuleService.remove(dataId);
    }


}